home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / linux-image-3.2.0-4-486.postinst < prev    next >
Encoding:
Text File  |  2012-12-19  |  22.4 KB  |  713 lines

  1. #! /usr/bin/perl
  2. #
  3. use strict;
  4. use warnings;
  5. use Cwd 'abs_path';
  6. use Debconf::Client::ConfModule qw(:all);
  7. use POSIX ();
  8. version('2.0');
  9. my $capb = capb('backup', 'escape');
  10.  
  11. $|=1;
  12.  
  13. # Predefined values:
  14. my $version           = "3.2.0-4-486";
  15. my $link_in_boot      = "";
  16. my $no_symlink        = "";
  17. my $do_symlink        = "Yes";  # target machine defined
  18. my $kimage            = "vmlinuz";
  19. my $initrd            = "YES";        # initrd kernel
  20. my $mkimage           = "";     # command to generate the initrd image
  21. my $use_hard_links    = ''; # hardlinks do not work across fs boundaries
  22. my $postinst_hook     = '';          #Normally we do not
  23. my $minimal_swap      = '';          # Do not swap symlinks
  24. my $ignore_depmod_err = '';          # normally we do not
  25. my $kernel_arch       = "x86";
  26. my $ramdisk           = '';
  27. my $package_name      = "linux-image-$version";
  28.  
  29. #known variables
  30. my $image_dest      = "/";
  31. my $realimageloc    = "/boot/";
  32. my $have_conffile   = "";
  33.  
  34. my $modules_base    = '/lib/modules';
  35. my $CONF_LOC        = '/etc/kernel-img.conf';
  36.  
  37. # Ignore all invocations except when called on to configure.
  38. exit 0 unless $ARGV[0] =~ /configure/;
  39.  
  40. my $DEBUG = 0;
  41.  
  42. # Do some preliminary sanity checks here to ensure we actually have an
  43. # valid image dir
  44. chdir('/')           or die "could not chdir to /:$!\n";
  45. die "Internal Error: ($realimageloc) is not a directory!\n"
  46.   unless -d $realimageloc;
  47.  
  48. if (-r "$CONF_LOC" && -f "$CONF_LOC"  ) {
  49.   if (open(CONF, "$CONF_LOC")) {
  50.     while (<CONF>) {
  51.       chomp;
  52.       s/\#.*$//g;
  53.       next if /^\s*$/;
  54.  
  55.       $do_symlink      = "" if /do_symlinks\s*=\s*(no|false|0)\s*$/i;
  56.       $no_symlink      = "" if /no_symlinks\s*=\s*(no|false|0)\s*$/i;
  57.       $link_in_boot    = "" if /link_in_boot\s*=\s*(no|false|0)\s*$/i;
  58.       $use_hard_links  = '' if /use_hard_links\s*=\s*(no|false|0)\s*$/i;
  59.       $minimal_swap    = '' if /minimal_swap\s*=\s*(no|false|0)\s*$/i;
  60.       $ignore_depmod_err = '' if /ignore_depmod_err\s*=\s*(no|false|0)\s*$/i;
  61.  
  62.       $do_symlink      = "Yes" if /do_symlinks\s*=\s*(yes|true|1)\s*$/i;
  63.       $no_symlink      = "Yes" if /no_symlinks\s*=\s*(yes|true|1)\s*$/i;
  64.       $link_in_boot    = "Yes" if /link_in_boot\s*=\s*(yes|true|1)\s*$/i;
  65.       $use_hard_links  = "Yes" if /use_hard_links\s*=\s*(yes|true|1)\s*$/i;
  66.       $minimal_swap    = 'Yes' if /minimal_swap\s*=\s*(yes|true|1)\s*$/i;
  67.       $ignore_depmod_err = 'Yes' if /ignore_depmod_err\s*=\s*(yes|true|1)\s*$/i;
  68.  
  69.       $image_dest      = "$1"  if /image_dest\s*=\s*(\S+)/i;
  70.       $postinst_hook   = "$1"  if /postinst_hook\s*=\s*(\S+)/i;
  71.       $mkimage         = "$1"  if /mkimage\s*=\s*(.+)$/i;
  72.       $ramdisk         = "$1"  if /ramdisk\s*=\s*(.+)$/i;
  73.     }
  74.     close CONF;
  75.     $have_conffile = "Yes";
  76.   }
  77. }
  78.  
  79.  
  80. if ($link_in_boot) {
  81.   $image_dest = $realimageloc;
  82. }
  83.  
  84. # Tack on at least one trainling /
  85. $image_dest = "$image_dest/";
  86. $image_dest =~ s|^/*|/|o;
  87. $image_dest =~ s|/+$|/|o;
  88.  
  89. if (! -d "$image_dest") {
  90.   die "Expected Image Destination dir ($image_dest) to be a valid directory!\n";
  91. }
  92.  
  93. # sanity
  94. if ($do_symlink && $no_symlink) {
  95.   warn "Both do_symlinks and no_symlinks options enabled; disabling no_symlinks\n";
  96.   $no_symlink = 0;
  97. }
  98.  
  99. # most of our work is done in $image_dest (nominally /)
  100. chdir("$image_dest") or die "could not chdir to $image_dest:$!\n";
  101.  
  102. $ENV{KERNEL_ARCH}=$kernel_arch if $kernel_arch;
  103.  
  104.  
  105. die "Internal Error: Could not find image (" . $realimageloc
  106.   . "$kimage-$version)\n" unless -e $realimageloc
  107.   . "$kimage-$version";
  108.  
  109.  
  110. ######################################################################
  111. ######################################################################
  112. ###########        Test whether a relative symlinkwould be OK #######
  113. ######################################################################
  114. ######################################################################
  115. sub test_relative {
  116.   my %params = @_;
  117.   my $cwd;
  118.  
  119.   die "Internal Error: Missing Required paramater 'Old Dir' "
  120.     unless $params{'Old Dir'};
  121.   die "Internal Error: Missing Required paramater New Dir' "
  122.     unless $params{'New Dir'};
  123.  
  124.  
  125.   die "Internal Error: No such dir $params{'Old Dir'} "
  126.     unless -d $params{'Old Dir'};
  127.   die "Internal Error: No such dir $params{'New Dir'} "
  128.     unless -d $params{'New Dir'};
  129.  
  130.   warn "Test relative: testing $params{'Old Dir'} -> $params{'New Dir'}"
  131.     if $DEBUG;
  132.   chomp($cwd = `pwd`);
  133.   chdir ($params{'New Dir'}) or die "Could not chdir to $params{'New Dir'}:$!";
  134.   my $ok = 0;
  135.   $params{'Old Dir'}  =~ s|^/*||o;
  136.   if (-d $params{'Old Dir'} ) {
  137.     if (defined $params{'Test File'}) {
  138.       if (-e $params{'Old Dir'} . $params{'Test File'}) {
  139.         $ok  = 1;
  140.       }
  141.     } else {
  142.       $ok = 1;                  # well, backward compatibility
  143.     }
  144.   }
  145.   chdir ($cwd) or die "Could not chdir to $params{'New Dir'}:$!";
  146.   return $ok;
  147. }
  148.  
  149.  
  150. sub spath {
  151.   my %params = @_;
  152.  
  153.   die "Missing Required paramater 'Old'" unless $params{'Old'};
  154.   die "Missing Required paramater 'New'" unless  $params{'New'};
  155.  
  156.   my @olddir  = split '/', `readlink -q -m $params{'Old'}`;
  157.   my @newdir  = split '/', `readlink -q -m $params{'New'}`;
  158.   my @outdir  = @olddir;
  159.  
  160.   my $out = '';
  161.   my $i;
  162.   for ($i = 0; $i <= $#olddir && $i <= $#newdir; $i++) {
  163.     $out++ if ($olddir[$i] ne $newdir[$i]);
  164.     shift @outdir unless $out;
  165.     unshift @outdir, ".." if $out;
  166.   }
  167.   if ($#newdir > $#olddir) {
  168.     for ($i=0; $i < $#newdir; $i++) {
  169.       unshift @outdir, "..";
  170.     }
  171.   }
  172.   return join ('/', @outdir);
  173. }
  174.  
  175. # This routine is invoked if there is a symbolic link in place
  176. # in $image_dest/$kimage -- so a symlink exists in the destination.
  177. # What we are trying to determine is if we need to move the symbolic link over
  178. # to the the .old location
  179. sub move_p {
  180.   my $kimage     = $_[0];       # Name of the symbolic link
  181.   my $image_dest = $_[1];       # The directory the links goes into
  182.   my $image_name = $_[2]; 
  183.   my $src_dir    = $_[3]; 
  184.   my $force_move = 0;
  185.   warn "Move?: kimage=$kimage, image_dest=$image_dest, \n" .
  186.     "\timage_name=$image_name, src_dir=$src_dir" if $DEBUG;
  187.  
  188.   if ($no_symlink) {
  189.     # we do not want links, yet we have a symbolic link here!
  190.     warn "found a symbolic link in " . $image_dest . "$kimage \n" .
  191.       "even though no_symlink is defined\n" if $no_symlink;
  192.     # make sure we change this state of affairs
  193.     $force_move = 1;
  194.     return $force_move;
  195.   }
  196.  
  197.   warn "DEBUG: OK. We found symlink, and we should have a symlink here.\n"
  198.     if $DEBUG;
  199.   my $vmlinuz_target = readlink "$kimage";
  200.   my $real_target = '';
  201.   my $target = `readlink -q -m "${realimageloc}${kimage}-$version"`;
  202.   $real_target = abs_path($vmlinuz_target) if defined($vmlinuz_target);
  203.  
  204.   if (!defined($vmlinuz_target) || ! -f "$real_target") {
  205.     # what, a dangling symlink?
  206.     warn "The link "  . $image_dest . "$kimage is a dangling link" .
  207.       "to $real_target\n";
  208.     $force_move = 1;
  209.     return $force_move;
  210.   }
  211.  
  212.  
  213.   warn "DEBUG: The link $kimage points to ($vmlinuz_target)\n" if $DEBUG;
  214.   warn "DEBUG: ($vmlinuz_target) is really ($real_target)\n" if $DEBUG;
  215.   my $cwd;
  216.   chomp ($cwd=`pwd`);
  217.   if ($vmlinuz_target !~ m|^/|o) {
  218.     $vmlinuz_target = $cwd . "/" . $vmlinuz_target;
  219.     $vmlinuz_target =~ s|/+|/|o;
  220.   }
  221.   $vmlinuz_target = `readlink -q -m $vmlinuz_target`;
  222.  
  223.   if ("$vmlinuz_target" ne "$target") {
  224.     warn "DEBUG: We need to handle this.\n" if $DEBUG;
  225.     if ($minimal_swap) {
  226.       warn "DEBUG: Minimal swap.\n" if $DEBUG;
  227.       if (-l "$kimage.old") {
  228.         warn "DEBUG: There is an old link at $kimage.old\n" if $DEBUG;
  229.         my $old_target = readlink "$kimage.old";
  230.         my $real_old_target = '';
  231.         $real_old_target=abs_path($old_target) if defined ($old_target);
  232.  
  233.         if ($real_old_target  && -f "$real_old_target") {
  234.           if ($old_target !~ m|^/|o) {
  235.             $old_target = $cwd . "/" . $old_target;
  236.             $old_target =~ s|/+|/|o;
  237.           }
  238.           $old_target = `readlink -q -m $old_target`;
  239.           if ("$old_target"  ne "$target") {
  240.             $force_move = 1;
  241.             warn "DEBUG: Old link ($old_target) does not point to us ($target)\n"
  242.               if $DEBUG;
  243.           } 
  244.           else {            # The .old points to the current
  245.             warn "$kimage.old --> $target -- doing nothing";
  246.             $force_move = 0;
  247.           }
  248.         } 
  249.         else { 
  250.           warn "DEBUG: Well, the old link does not exist -- so we move\n"
  251.             if $DEBUG;
  252.           $force_move = 1;
  253.         }
  254.       } 
  255.       else {
  256.         warn "DEBUG: No .old link -- OK to move\n"
  257.           if $DEBUG;
  258.         $force_move = 1;
  259.       }
  260.     } 
  261.     else {
  262.       warn "DEBUG: ok, minimal swap is no-- so we move.\n"
  263.         if $DEBUG;
  264.       $force_move = 1;
  265.     }
  266.   }
  267.   else {                  # already have proper link
  268.     warn "$kimage($vmlinuz_target) points to $target ($real_target) -- doing nothing";
  269.     $force_move = 0;
  270.   }
  271.   return $force_move;
  272. }
  273.  
  274.  
  275. # This routine moves the symbolic link around (/vmlinuz -> /vmlinuz.old)
  276. # It pays attention to whether we should the fact whether we should be using
  277. # hard links or not.
  278. sub really_move_link {
  279.   my $kimage     = $_[0];       # Name of the symbolic link
  280.   my $image_dest = $_[1];       # The directory the links goes into
  281.   my $image_name = $_[2]; 
  282.   my $src_dir    = $_[3]; 
  283.   warn "really_move_link: kimage=$kimage, image_dest=$image_dest\n" .
  284.     "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
  285.  
  286.   # don't clobber $kimage.old quite yet
  287.   rename("$kimage", "$kimage.$$") ||
  288.     die "failed to move " . $image_dest . "$kimage:$!";
  289.   my $Old = $src_dir;
  290.   my $cwd;
  291.  
  292.   chomp($cwd=`pwd`);
  293.   if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
  294.                      'Test File' => "$image_name")) {
  295.     $Old   =~ s|^/*||o;
  296.   }
  297.   # Special case is they are in the same dir
  298.   my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
  299.   $Old ="" if $rel_path =~ m/^\s*$/o;
  300.  
  301.   if ($use_hard_links =~ m/YES/i) {
  302.     if (! link("${Old}${image_name}", "$kimage")) {
  303.       rename("$kimage.$$", "$kimage");
  304.       die("Failed to link ${Old}${image_name} to " .
  305.           "${image_dest}${kimage}.\n");
  306.     }
  307.   } 
  308.   else {
  309.     if (! symlink("${Old}${image_name}", "$kimage")) {
  310.       rename("$kimage.$$", "$kimage");
  311.       die("Failed to symbolic-link ${Old}${image_name} to " .
  312.           "${image_dest}${kimage}.\n");
  313.     }
  314.   }
  315.  
  316.   # Ok, now we may clobber the previous .old file
  317.   if (-l "$kimage.old" || ! -e "$kimage.old" ) {
  318.     rename("$kimage.$$", "$kimage.old");
  319.   }
  320.   else {
  321.     warn "$kimage.old is not a symlink, not clobbering\n";
  322.     warn "rm $kimage.$$";
  323.   }
  324. }
  325.  
  326. # This routine handles a request to do symlinks, but there is no
  327. # symlink file already there.  Either we are supposed to use copy, or we are
  328. # installing on a pristine system, or the user does not want symbolic links at
  329. # all.  We use a configuration file to tell the last two cases apart, creating
  330. # a config file if needed.
  331. sub handle_missing_link {
  332.   my $kimage     = $_[0];       # Name of the symbolic link
  333.   my $image_dest = $_[1];       # The directory the links goes into
  334.   my $image_name = $_[2]; 
  335.   my $src_dir    = $_[3]; 
  336.   warn "handle_missing_link: kimage=$kimage, image_dest=$image_dest\n" .
  337.     "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
  338.  
  339.   if ($no_symlink) {
  340.     my $ret = system("cp -a --backup=t " . $realimageloc .
  341.                      "$image_name "   . " $kimage");
  342.     if ($ret) {
  343.       die("Failed to copy " . $realimageloc . "$image_name to "
  344.           . $image_dest . "$kimage .\n");
  345.     }
  346.   }
  347.  
  348.   if (! $no_symlink && $do_symlink =~ /Yes/i) {
  349.     my $Old = $realimageloc;
  350.     my $New = $image_dest;
  351.     my $Name = "$image_name";
  352.     my $Link_Dest = "$kimage";
  353.  
  354.     if (test_relative ('Old Dir' => $Old,
  355.                        'New Dir' => $New,
  356.                        'Test File' => $Name)) {
  357.       $Old   =~ s|^/*||o;
  358.     }
  359.     # Special case is they are in the same dir
  360.     my $rel_path = spath('Old' => "$Old", 'New' => "$New" );
  361.     $Old ="" if $rel_path =~ m/^\s*$/o;
  362.  
  363.     symlink($Old . "$Name", "$Link_Dest") ||
  364.       die("Failed to symbolic-link ${Old}$Name to $Link_Dest.\n");
  365.  
  366.   }
  367. }
  368.  
  369. # This routine handles the rest of the cases, where the user has requested 
  370. # non-traditional handling, like using cp or hard links.
  371. sub handle_non_symlinks {
  372.   my $kimage     = $_[0];       # Name of the symbolic link
  373.   my $image_dest = $_[1];       # The directory the links goes into
  374.   my $image_name = $_[2]; 
  375.   my $src_dir    = $_[3]; 
  376.   warn "handle_non_link: kimage=$kimage, image_dest=$image_dest\n" .
  377.     "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
  378.  
  379.   # Save the current image. We do this in all four cases
  380.   rename("$kimage", "$kimage.$$") || 
  381.     die "failed to move " . $image_dest . "$kimage:$!";
  382.  
  383.   ##,#### 
  384.   # case One
  385.   #`####
  386.   if ($no_symlink) {
  387.     # Maybe /$image_dest is on a dos system?
  388.     my $ret = system("cp -a --backup=t " . $realimageloc
  389.                      . "$image_name " . "$kimage");
  390.     if ($ret) {
  391.       if (-e "$kimage.$$") {
  392.         rename("$kimage.$$", "$kimage");
  393.       }
  394.       die("Failed to copy " . $realimageloc . "$image_name to "
  395.           . $image_dest . "$kimage .\n");
  396.     }
  397.   }
  398.   ##,#### 
  399.   # case Two
  400.   #`####
  401.   elsif ($use_hard_links =~ m/YES/i ) {
  402.     # Ok then. this ought to be a hard link, and hence fair game
  403.     # don't clobber $kimage.old quite yet
  404.     my $Old = $realimageloc;
  405.     my $cwd;
  406.     chomp($cwd=`pwd`);
  407.     if (test_relative ('Old Dir' => $Old, 'New Dir' => $cwd,
  408.                        'Test File' => "$image_name")) {
  409.       $Old   =~ s|^/*||o;
  410.     }
  411.     # Special case is they are in the same dir
  412.     my $rel_path = spath('Old' => "$Old", 'New' => "$cwd" );
  413.     $Old ="" if $rel_path =~ m/^\s*$/o;
  414.  
  415.     if (! link($Old . "$image_name", "$kimage")) {
  416.       rename("$kimage.$$", "$kimage");
  417.       die("Failed to hard link " . $realimageloc . "$image_name to "
  418.           . $image_dest . "$kimage .\n");
  419.     }
  420.   }
  421.   ##,####
  422.   # case Three
  423.   #`####
  424.   else {
  425.     # We just use cp
  426.     my $ret = system("cp -a --backup=t " . $realimageloc
  427.                      . "$image_name " . "$kimage");
  428.     if ($ret) {
  429.       if (-e "$kimage.$$") {
  430.         rename("$kimage.$$", "$kimage");
  431.       }
  432.       die("Failed to copy " . $realimageloc . "$image_name to "
  433.           . $image_dest . "$kimage .\n");
  434.     }
  435.   }
  436.   # Ok, now we may clobber the previous .old file
  437.   rename("$kimage.$$", "$kimage.old") if -e "$kimage.$$";
  438. }
  439.  
  440. # This routine is responsible for setting up the symbolic links
  441. # So, the actual kernel image lives in
  442. # $realimageloc/$image_name (/boot/vmlinuz-2.6.12).
  443. # This routine creates symbolic links in $image_dest/$kimage (/vmlinuz)
  444. sub image_magic {
  445.   my $kimage     = $_[0];       # Name of the symbolic link
  446.   my $image_dest = $_[1];       # The directory the links goes into
  447.   my $image_name = "$kimage-$version";
  448.   my $src_dir    = $realimageloc;
  449.   warn "image_magic: kimage=$kimage, image_dest=$image_dest\n" .
  450.     "\t image_name=$image_name, src_dir=$src_dir" if $DEBUG;
  451.  
  452.   if (-l "$kimage") {           # There is a symbolic link
  453.     warn "DEBUG: There is a symlink for $kimage\n" if $DEBUG;
  454.     my $force_move = move_p($kimage, $image_dest, $image_name, $src_dir);
  455.  
  456.     if ($force_move) {
  457.       really_move_link($kimage, $image_dest, $image_name, $src_dir);
  458.     }
  459.   }
  460.   elsif (! -e "$kimage") {
  461.     # Hmm. Pristine system? How can that be? Installing from scratch?
  462.     # Or maybe the user does not want a symbolic link here.
  463.     # Possibly they do not want a link here. (we should be in /
  464.     # here[$image_dest, really]
  465.     handle_missing_link($kimage, $image_dest, $image_name, $src_dir);
  466.   }
  467.   elsif (-e "$kimage" ) {
  468.     # OK, $kimage exists -- but is not a link
  469.     handle_non_symlinks($kimage, $image_dest, $image_name, $src_dir);
  470.   }
  471. }
  472.  
  473. ######################################################################
  474. ######################################################################
  475. ######################################################################
  476. ######################################################################
  477.  
  478. sub do_modules {
  479.   print STDERR "Running depmod.\n";
  480.   my $ret = system("depmod -a -F $realimageloc/System.map-$version $version");
  481.   my $exit_value  = $? >> 8;
  482.   my $signal_num  = $? & 127;
  483.   my $dumped_core = $? & 128;
  484.   if ($ret) {
  485.     my $seen;
  486.     my $answer;
  487.     my $question;
  488.     $question = "${package_name}/postinst/depmod-error-initrd-$version";
  489.  
  490.     ($ret,$seen) = fset ("$question", 'seen', 'false');
  491.     die "Error setting debconf flags in $question: $seen" if $ret;
  492.  
  493.     $ret = subst("$question", 'modules_base', "$modules_base");
  494.     die "Error setting debconf substitutions in $question: $seen" if $ret;
  495.  
  496.     $ret = subst("$question", 'SIGNAL', ", and got a signal $signal_num");
  497.     die "Error setting debconf substitutions in $question: $seen" if $ret;
  498.  
  499.     if ($dumped_core) {
  500.       $ret = subst("$question", 'CORE', ", and dumped core");
  501.       die "Error setting debconf substitutions in $question: $seen" if $ret;
  502.     }
  503.     else {
  504.       $ret = subst("$question", 'CORE', " ");
  505.       die "Error setting debconf substitutions in $question: $seen" if $ret;
  506.     }
  507.  
  508.     ($ret,$seen) = input('medium', "$question");
  509.     if ($ret && $ret != 30 ) {
  510.       die "Error setting debconf question $question: $seen";
  511.     }
  512.  
  513.     ($ret,$seen) = go ();
  514.     if ($ret && $ret != 30 ) {
  515.       die "Error asking debconf question $question: $seen";
  516.     }
  517.  
  518.     ($ret,$answer) = get("$question");
  519.     die "Error retreiving answer for $question: $answer" if $ret;
  520.  
  521.     if (! $ignore_depmod_err) {
  522.       if ($answer =~ /^(y|t)/i) {
  523.         exit(1);
  524.       }
  525.       else {
  526.         print STDERR "Ok, continuing as directed\n";
  527.       }
  528.     }
  529.   }
  530.  
  531.   # If we are installing (not upgrading) a package for a newer
  532.   # upstream version than that of the running kernel, check whether
  533.   # the user might be missing necessary firmware, perhaps because
  534.   # it has now been removed from the kernel.
  535.   #
  536.   # We base this check on the modules used in the running kernel and
  537.   # the corresponding (by name) modules in the new kernel.  This is
  538.   # not entirely accurate because:
  539.   # 1. A device may now be handled by a module with a different name,
  540.   #    leading us to miss the dependency
  541.   # 2. A device may be handled by a module that needs firmware only
  542.   #    for some other device, leading us to claim a dependency wrongly
  543.  
  544.   if (!defined($ARGV[1]) || $ARGV[1] eq '') {
  545.     sub version_code {
  546.       my $version = shift;
  547.       $version =~ s/^2\.(\d+)\.(\d+).*/2*65536 + $1*256 + $2/e
  548.     or $version =~ s/^(\d+)\.(\d+).*/$1*65536 + $2*256/e
  549.     or $version = 0;
  550.       return $version;
  551.     }
  552.     (undef, undef, my $running_version) = POSIX::uname();
  553.  
  554.     if (version_code($version) > version_code($running_version)) {
  555.       my $missing = '';
  556.       my %module_paths;
  557.       open(DEP, "<$modules_base/$version/modules.dep") or return;
  558.       while (<DEP>) {
  559.     if (m|(.*/([^/]*)\.ko):|) {
  560.       my ($path, $module) = ($1, $2);
  561.       $module =~ s/-/_/g;
  562.       $module_paths{$module} = $path;
  563.     }
  564.       }
  565.       close(DEP);
  566.       open(MODULES, '</proc/modules') or return;
  567.       while (<MODULES>) {
  568.     s/ .*//s;
  569.     my $module = $_;
  570.     my $module_path = $module_paths{$module};
  571.     if (defined($module_path)) {
  572.       my $first = 1;
  573.       if ($module_path !~ m|^/|) {
  574.         $module_path = "$modules_base/$version/$module_path";
  575.       }
  576.       open(MODINFO, "modinfo -F firmware '$module_path' |");
  577.       while (<MODINFO>) {
  578.         chomp;
  579.         my $firmware = $_;
  580.         unless (-e "/lib/firmware/$firmware" ||
  581.             -e "/lib/firmware/$version/$firmware") {
  582.           if ($first) {
  583.         $missing .= "\\n" if $missing ne '';
  584.         $missing .= "$module: ";
  585.         $first = 0;
  586.           } else {
  587.         $missing .= ', ';
  588.           }
  589.           $missing .= $firmware;
  590.         }
  591.       }
  592.       close(MODINFO);
  593.     }
  594.       }
  595.       close(MODULES);
  596.  
  597.       if ($missing ne '') {
  598.     my ($ret, $seen);
  599.     my $text = "${package_name}/postinst/missing-firmware-${version}";
  600.  
  601.     ($ret, $seen) = subst($text, 'runningversion', $running_version);
  602.     die "Error setting debconf substitutions in $text: $seen" if $ret;
  603.  
  604.     ($ret, $seen) = subst($text, 'version', $version);
  605.     die "Error setting debconf substitutions in $text: $seen" if $ret;
  606.  
  607.     ($ret, $seen) = subst($text, 'missing', $missing);
  608.     die "Error setting debconf substitutions in $text: $seen" if $ret;
  609.  
  610.     ($ret, $seen) = input('high', $text);
  611.     if ($ret && $ret != 30) {
  612.       die "Error setting debconf question $text: $seen";
  613.     }
  614.  
  615.     ($ret, $seen) = go();
  616.     if ($ret && $ret != 30) {
  617.       die "Error asking debconf question $text: $seen";
  618.     }
  619.       }
  620.     }
  621.   }
  622. }
  623.  
  624. # We may not have any modules installed
  625. if (-d "$modules_base/$version") {
  626.   &do_modules();
  627. }
  628.  
  629.  
  630. # Warn if we are ignoring the old ramdisk setting
  631. if ($ramdisk =~ /\S/) {
  632.     my ($question, $ret, $seen);
  633.     $question = "${package_name}/postinst/ignoring-ramdisk";
  634.     ($ret,$seen) = input('high', "$question");
  635.     die "Error setting debconf question $question: $seen" if $ret && $ret != 30;
  636.     ($ret,$seen) = go();
  637.     die "Error asking debconf question $question: $seen" if $ret && $ret != 30;
  638. }
  639.  
  640. # Only change the symlinks if we are not being upgraded
  641. if (! defined $ARGV[1] || ! $ARGV[1] || $ARGV[1] =~ m/<unknown>/o) {
  642.   image_magic($kimage, $image_dest);
  643.   if ($initrd) {
  644.     image_magic("initrd.img", $image_dest);
  645.   }
  646. }
  647. else {
  648.   if (! -e "$kimage") {
  649.     handle_missing_link($kimage, $image_dest, "$kimage-$version", 
  650.                         $realimageloc);
  651.   }
  652.   if ($initrd && ! -e "initrd.img") {
  653.     handle_missing_link("initrd.img", $image_dest, "initrd.img-$version",
  654.             $realimageloc);
  655.   }
  656. }
  657.  
  658. # set the env var stem
  659. $ENV{'STEM'} = "linux";
  660. sub run_hook {
  661.   my $type   = shift;
  662.   my $script = shift;
  663.  
  664.   print STDERR "Running $script.\n";
  665.   system ("$script $version $realimageloc$kimage-$version") &&
  666.     print STDERR "User $type hook script [$script] ";
  667.   if ($?) {
  668.     if ($? == -1) {
  669.       print STDERR "failed to execute: $!\n";
  670.     }
  671.     elsif ($? & 127) {
  672.       printf STDERR "died with signal %d, %s coredump\n",
  673.         ($? & 127),  ($? & 128) ? 'with' : 'without';
  674.     }
  675.     else {
  676.       printf STDERR "exited with value %d\n", $? >> 8;
  677.     }
  678.     exit $? >> 8;
  679.   }
  680. }
  681.  
  682. my $options;
  683. for (@ARGV) {
  684.     s,','\\'',g;
  685.     $options .= " '$_'";
  686. }
  687. $ENV{'DEB_MAINT_PARAMS'}="$options";
  688.  
  689. ## Run user hook script here, if any
  690. if ($postinst_hook) {
  691.   &run_hook("postinst", $postinst_hook);
  692. }
  693.  
  694. if (-d "/etc/kernel/postinst.d") {
  695.   print STDERR "Examining /etc/kernel/postinst.d.\n";
  696.   system ("run-parts --verbose --exit-on-error --arg=$version " .
  697.           "--arg=$realimageloc$kimage-$version " .
  698.           "/etc/kernel/postinst.d") &&
  699.             die "Failed to process /etc/kernel/postinst.d";
  700. }
  701.  
  702. if (-d "/etc/kernel/postinst.d/$version") {
  703.   print STDERR "Examining /etc/kernel/postinst.d/$version.\n";
  704.   system ("run-parts --verbose --exit-on-error --arg=$version " .
  705.           "--arg=$realimageloc$kimage-$version " .
  706.           "/etc/kernel/postinst.d/$version") &&
  707.             die "Failed to process /etc/kernel/postinst.d/$version";
  708. }
  709.  
  710. exit 0;
  711.  
  712. __END__
  713.